import axios from "axios";

const instance = axios.create({
  // baseURL: "http://124.221.203.243:8083",
  baseURL: "http://124.221.58.106:8082",
  // baseURL: "http://localhost:1337",
  // baseURL: "/api",
  timeout: 5000, //请求超时时间
});
// 这是拦截器
// Add a request interceptor
// 请求拦截
instance.interceptors.request.use(
  function (config) {
    // Do something before request is sent
    // config.headers.token = localStorage.getItem("token")
    //   ? localStorage.getItem("token")
    //   : "";
    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// Add a response interceptor
// 响应拦截
instance.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  }
);

// 请求方式
export const get = (url, params) => instance.get(url, { params });

export const post = (url, data) => instance.post(url, data);

export const del = (url, data) => instance.delete(url, data);

export const put = (url, data) => instance.delete(url, data);
